<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;

Route::get('index', 'Index/index');

Route::group('api/', function () {
    Route::group('user', function () {
        Route::post('', 'User/save');
        Route::post('token', 'User/login');
        Route::delete('token', 'User/logout');
        Route::delete(':id', 'User/delete');
        Route::patch('password', 'User/reset_password');
        Route::patch('phone', 'User/reset_phone');
        Route::patch('avatar', 'User/upload_avatar');
        Route::patch(':id/pass', 'User/apply_pass');
        Route::patch(':id/reject', 'User/apply_reject');
        Route::get('', 'User/index');
        Route::get(':id', 'User/read'); // 这一条要放到最后，否则会出现意想不到的错误
    });

    Route::group('sms', function () {
        Route::post('token', 'Sms/send_login_sms');
        Route::post('phone', 'Sms/send_reset_phone_sms');
        Route::post('password', 'Sms/send_find_password_sms');
    });

    Route::group('userGroup', function () {
        Route::resource('', 'UserGroup')
            ->except(['create', 'edit']);
    });

    Route::group('rule', function () {
        Route::resource('', 'Rule')
            ->except(['create', 'edit']);
    });

    Route::group('option', function () {
        Route::resource('', 'Option')
            ->except(['create', 'edit']);
    });

    Route::group('loan', function () {
        Route::resource('', 'Loan')
            ->except(['create', 'edit']);
        Route::patch(':id/pass', 'Loan/pass');
        Route::patch(':id/reject', 'Loan/reject');
    });

    Route::group('inventory', function () {
        Route::resource('', 'Inventory')
            ->except(['create', 'edit']);
        Route::patch(':id/pass', 'Inventory/pass');
        Route::patch(':id/reject', 'Inventory/reject');
        Route::patch(':id/repay', 'Inventory/repay');
    });

    Route::group('material', function () {
        Route::get('getId', 'Material/get_material_id');
        Route::patch('', 'Material/warehousing');
        Route::resource('', 'Material')
            ->except(['create', 'edit']);
    });

    Route::group('machine', function () {
        Route::resource('', 'Machine')
            ->except(['create', 'edit']);
    });

    Route::group('warehouse', function () {
        Route::get(':id/materials', 'Warehouse/getMaterialList');
        Route::resource('', 'Warehouse')
            ->except(['create', 'edit']);
    });

    Route::group('attach', function () {
        Route::get('refresh', 'Attach/uploadToUpyun');
        Route::resource('', 'Attach')
            ->except(['create', 'edit']);
    });

    Route::group('log', function () {
        Route::resource('', 'Log')
            ->except(['create', 'edit']);
    });

    Route::group('category', function () {
        Route::resource('', 'Category')
            ->except(['create', 'edit']);
    });

    Route::group('application', function () {
        Route::resource('', 'Application')
            ->except(['create', 'edit']);
        Route::patch(':id/pass', 'Application/pass');
        Route::patch(':id/reject', 'Application/reject');
    });

    Route::group('article', function () {
        Route::resource('', 'Article')
            ->except(['create', 'edit']);
    });

    Route::group('search', function () {
        Route::get('user', 'Search/user');
        Route::post('material', 'Search/material');
        Route::post('machine', 'Search/machine');
    });

    Route::group('update-log', function () {
        Route::resource('', 'UpdateLog')
            ->except(['create', 'edit']);
    });
})->prefix('api/')->allowCrossDomain();

Route::miss(function () {
    return '404 Not Found!';
});
